package ch.dbphpTesting.diplomarbeit;

import java.util.ArrayList;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ArrayAdapter;


public class DBTestActivity extends ListActivity {
	
	private ListActivity activity;
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	
        super.onCreate(savedInstanceState);
        activity = this;
        
        
        new DownloadUserData().execute();
    }
    
	private class DownloadUserData extends AsyncTask<Void, Integer, ArrayList<String>>{
		
		ProgressDialog prog;
		
		protected void onPreExecute (){
			
		    prog = new ProgressDialog(activity);
//		    prog.setTitle("Titel");
		    prog.setMessage("Downloading data...");       
		    prog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		    prog.show();
		}

		@Override
		protected ArrayList<String> doInBackground(Void... params) {
			
			ArrayList<String> data = new ConnectionDB().getData();
			return data;
		}
		
		protected void onPostExecute(ArrayList<String> items) {
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			prog.dismiss();
			ArrayAdapter<String> addapter = new ArrayAdapter<String>(activity, android.R.layout.simple_list_item_1, items);
			activity.setListAdapter(addapter);
	     }
    }
}